package com.wjb.xietong.ota.comment;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.wjb.xietong.R;
import com.wjb.xietong.TestData;
import com.wjb.xietong.component.AppGlobal;
import com.wjb.xietong.ota.BaseOTA;
import com.wjb.xietong.ota.task.TaskInfo;

public class OTACommentList extends BaseOTA {


	private ExpandableListView mCommentListView;
	private CommentListAdapter mAdapter;
	
	private ArrayList<TaskInfo> taskList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		taskList = TestData.Instance().getNoFinishTaskList();
		
		setContentField(getLayoutInflater().inflate(R.layout.page_comment_list,
				null));

		setTopBarAndAction(getResources().getString(R.string.STR_PROJECT_01),
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						app_.getActManager().popActivity();
					}
				}, null);

	}

	@Override
	protected void findView(View v) {
		super.findView(v);
		ColorDrawable drawable_tranparent_ = new ColorDrawable(Color.TRANSPARENT);  

		mCommentListView = (ExpandableListView) v.findViewById(R.id.id_expandablelist);
		mCommentListView.setCacheColorHint(Color.TRANSPARENT);  
		mCommentListView.setDividerHeight(0);  
		mCommentListView.setGroupIndicator(null);  
        /*隐藏选择的黄色高亮*/  
        mCommentListView.setSelector(drawable_tranparent_);  
        
		mAdapter = new CommentListAdapter(this);
		mCommentListView.setAdapter(mAdapter);
		
		final int SIZE = mAdapter.getGroupCount();
		for(int i = 0; i < SIZE; i++){
			mCommentListView.expandGroup(i);
		}
		
	}

	@Override
	protected void setOnClickEvent() {
		super.setOnClickEvent();
	}

	public class CommentListAdapter extends BaseExpandableListAdapter{

		private LayoutInflater mInflater;

		public CommentListAdapter(Context context) {
			this.mInflater = LayoutInflater.from(context);
		}
		
		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,  
                ViewGroup parent) {
			ChildHolder holder;
			if (convertView == null) {
				convertView = mInflater.inflate(R.layout.item_comment_child,
						null);
				holder = new ChildHolder();
				/* 得到各个控件的对象 */
				holder.txtComment = (TextView) convertView.findViewById(R.id.id_child_txt_comment);
				holder.txtCommentNum = (TextView) convertView.findViewById(R.id.id_child_txt_comment_num);
				holder.txtPraiseNum = (TextView) convertView.findViewById(R.id.id_child_txt_praise_num);

				convertView.setTag(holder); // 绑定ViewHolder对象
			} else {
				holder = (ChildHolder) convertView.getTag(); // 取出ViewHolder对象
			}

			return convertView;
		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			return 1;
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return 10;
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getGroupView(int position, boolean isExpanded, View convertView,
				ViewGroup parent) {
			GroupHolder holder;
			if (convertView == null) {
				convertView = mInflater.inflate(R.layout.item_comment_group,
						null);
				holder = new GroupHolder();
				/* 得到各个控件的对象 */
				holder.imgPortrait = (ImageView) convertView.findViewById(R.id.id_group_img_portrait);
				holder.txtName = (TextView) convertView.findViewById(R.id.id_group_txt_name);
				holder.txtTime = (TextView) convertView.findViewById(R.id.id_group_txt_time);
				holder.txtFrom = (TextView) convertView.findViewById(R.id.id_group_txt_from);

				convertView.setTag(holder); // 绑定ViewHolder对象
			} else {
				holder = (GroupHolder) convertView.getTag(); // 取出ViewHolder对象
			}
			
			/*判断是否group张开，来分别设置背景图*/  
            if(isExpanded){  
                convertView.setBackgroundResource(R.drawable.group_e);  
            }else{  
                convertView.setBackgroundResource(R.drawable.group);  
            } 

			return convertView;
		}

		@Override
		public boolean hasStableIds() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isChildSelectable(int arg0, int arg1) {
			// TODO Auto-generated method stub
			return false;
		}
		
		/* 存放控件 的ViewHolder */
		public final class GroupHolder {
			public ImageView imgPortrait;
			public TextView txtName;
			public TextView txtTime;
			public TextView txtFrom;
		}
		
		public final class ChildHolder {
			public TextView txtComment;
			public TextView txtCommentNum;
			public TextView txtPraiseNum;
		}
	}
	
}
